﻿var grid = null;

$(function () {
    $("#txtStartDate,#txtEndDate").ligerDateEditor({
        showTime: false,
        format: "yyyy-MM-dd",
        width: 100,
        cancelable: false
    });

    $("#isChange").ligerComboBox({
        width: 60,
        value: 0,
        valueFieldID: 'hdnIsChange'
    });

    $("#btnSearch").click(function () {
        search();
    });
    $("#btnSignIn").click(function () {
        edit();
    });
    $('#btnSearch').click();
});


//查询签到
function search(pageNumber) {
    var queryData = {
        startDate: $("#txtStartDate").val(),
        endDate: $("#txtEndDate").val(),
        isChange: $("#hdnIsChange").val(),
        name: $("#txtName").length == 0 ? "" : $("#txtName").val()
    };
    initTable(queryData, pageNumber);
}

//加载列表
function initTable(queryData, pageNumber) {
    $("#maingrid").ligerGrid({
        height: '100%',
        url: '/Scheduling/SchedulingSignIn/Search?ram=' + Math.random(),
        parms: queryData,
        page: pageNumber,
        pageSize: 30,
        rownumbers: true,
        heightDiff: -5,
        columns: [
        { display: '姓名', name: 'PersonnelName', width: 100 },
        { display: '日期', name: 'SignInDate', width: 100 },
        {
            display: '排班班别', name: '', width: 250, render: function (row) {
                var html = "";
                if (row.OldCategoryId != null && row.OldCategoryId != "") {
                    var idList = row.OldCategoryId.split('|');
                    var codeList = row.OldCategoryCode.split('|');
                    var colorList = row.OldCategoryColor.split('|');
                    for (var i = 0; i < idList.length; i++) {
                        html += "<font style=\"margin-left:4px; color:" + colorList[i] + "\">" + codeList[i] + "</font>";
                    }
                }
                return html;
            }
        },
        {
            display: '签到班别', name: '', width: 250, render: function (row) {
                var html = "";
                if (row.CategoryId != null && row.CategoryId != "") {
                    var idList = row.CategoryId.split('|');
                    var codeList = row.CategoryCode.split('|');
                    var colorList = row.CategoryColor.split('|');
                    for (var i = 0; i < idList.length; i++) {
                        html += "<font style=\"margin-left:4px; color:" + colorList[i] + "\">" + codeList[i] + "</font>";
                    }
                }
                return html;
            }
        }]
    });
    GridNoData($("#maingrid"));
}

//添加/编辑
function edit(id) {
    $.ligerDialog.open({
        height: 360,
        width: 420,
        title: '排班签到',
        url: '/Scheduling/SchedulingSignIn/Edit?id=' + id,
        showMax: false,
        showToggle: false,
        showMin: false,
        isResize: false,
        slide: false,
        data: {},
        buttons: [{
            text: '回调函数', onclick: function (i, d) {
                $("#btnSearch").click();
            }
        }]
    });
    $(".l-dialog-buttons").hide();
}